#include <iostream>
#include "Player.h"


using namespace std;



Player::Player()
{
}

Player::Player(GfxEngine* engine){
   this->icon = new Image("res/icon.png", 32, 32);
   x = 200;
   y = 200;
   engine->add_image(icon);
   gravity = 1;
   v_speed = 0;
}

Player::~Player()
{
    delete this->icon;
}

void Player::update(KeyboardState* keyState)
{
    if (keyState->K_Left.state == KeyPressed)
        this->x -= 4;
    if (keyState->K_Right.state == KeyPressed)
        this->x += 4;
    if (keyState->K_Up.state == KeyPressed && 
        y >= 480 - 64 && v_speed == 0)
        this->v_speed -= 24;
    
    //cout << v_speed << endl;
    
    
    
    if ((this->y + this->v_speed) >= 480 - 64){
        this->y = 480 - 64;
        this->v_speed = 0;
    } else {
        this->v_speed += gravity;
        this->y += v_speed;
    }
    
    this->icon->update(this->x, this->y);
}
